package Sort;

public class InsertSort {
    public void insertionSort(int[] nums) {
        int n = nums.length;
        for (int i = 1; i < n; i++) {
            int base = nums[i];
            int j = i - 1;
            while (j >= 0 && nums[j] > base) {
                nums[j + 1] = nums[j];
                j--;
            }
            nums[j + 1] = base;
        }
    }

    public static void main(String[] args) {
        int[] nums = { 1, 4, 7, 9, 2, 6 };
        InsertSort insertSort = new InsertSort();
        insertSort.insertionSort(nums);
        for (int num : nums) {
            System.out.println(num);
        }
    }
}

